const hideHeaderRoute = ['user','search'];
const state = {
    route: '',
    showTab: false,
    showHeader: false,
    showHeaderBack: false,
    showHeaderRight: false,
    pageTitle:''
};

export const getterTypes = {
    route: "[app] route",
    showTab: "[app] showTab",
    showHeader: "[app] showHeader",
    showHeaderBack: "[app] showHeaderBack",
    showHeaderRight: "[app] showHeaderRight",
    pageTitle:'[app] pageTitle'
}

const getters = {
    [getterTypes.route]: state => state.route,
    [getterTypes.showTab]: state => state.showTab,
    [getterTypes.showHeader]: state => state.showHeader,
    [getterTypes.showHeaderBack]: state => state.showHeaderBack,
    [getterTypes.showHeaderRight]: state => state.showHeaderRight,
    [getterTypes.pageTitle]: state => state.pageTitle,
};

export const mutationTypes = {
    setRoute: "[app] route",
    setTabShow: "[app] showTab",
    setHeaderShow: "[app] showHeader",
    setHeaderBackShow: "[app] showHeaderBack",
    setHeaderRightShow: "[app] showHeaderRight",
    setPageTitle: "[app] pageTitle",
}

const mutations = {
    [mutationTypes.setRoute](state, route) {
        state.route = route
    },
    [mutationTypes.setTabShow](state) {
        if (state.route.meta.isTab==undefined||!state.route.meta.isTab) {
            state.showTab = false
        } else {
            state.showTab = true
        }
    },
    [mutationTypes.setHeaderShow](state) {
        const hide = hideHeaderRoute.indexOf(state.route.name) > -1;
        if (hide) {
            state.showHeader = false
        } else {
            state.showHeader = true;
        }
    },
    [mutationTypes.setHeaderBackShow](state) {
        if (state.route.meta.isTab==undefined||!state.route.meta.isTab) {
            state.showHeaderBack = true
        } else {
            state.showHeaderBack = false
        }
    },
    [mutationTypes.setHeaderRightShow](state) {
        console.log('111state.route',state.route)
        if (state.route.meta.isTab) {
            state.showHeaderRight = true
        } else {
            state.showHeaderRight = false
        }
    },
    [mutationTypes.setPageTitle](state) {
        const title = state.route.meta.title;
       state.pageTitle = title;
    }
};

export const actionTypes = {
    setRoute: "[app] setRoute",
    setTabShow: "[app] setTabShow",
    setHeaderShow: "[app] setHeaderShow",
    setHeaderBackShow: '[app] setHeaderBackShow',
    setHeaderRightShow: '[app] setHeaderRightShow'
}
const actions = {
    [actionTypes.setRoute](context, route) {
        return new Promise(resolve => {
            context.commit(mutationTypes.setRoute, route)
            context.commit(mutationTypes.setPageTitle)
            resolve()
        })
    },
    [actionTypes.setTabShow](context) {
        return new Promise(resolve => {
            context.commit(mutationTypes.setTabShow)
            resolve()
        })
    },
    [actionTypes.setHeaderShow](context) {
        return new Promise(resolve => {
            context.commit(mutationTypes.setHeaderShow)
            resolve()
        })
    },
    [actionTypes.setHeaderBackShow](context) {
        return new Promise(resolve => {
            context.commit(mutationTypes.setHeaderBackShow)
            resolve()
        })
    },
    [actionTypes.setHeaderRightShow](context) {
        return new Promise(resolve => {
            context.commit(mutationTypes.setHeaderRightShow)
            resolve()
        })
    }
};



export default {
    state,
    mutations,
    actions,
    getters,
}